//===========================================================================
// This file was modified as part of an ASP.NET 2.0 Web project conversion.
// The class name was changed and the class modified to inherit from the abstract base class 
// in file 'App_Code\Migrated\personnel\Stub_exceptionreport_aspx_cs.cs'.
// During runtime, this allows other classes in your web application to bind and access 
// the code-behind page using the abstract base class.
// The associated content page 'personnel\exceptionreport.aspx' was also modified to refer to the new class name.
// For more information on this code pattern, please refer to http://go.microsoft.com/fwlink/?LinkId=46995 
//===========================================================================

using System;
using System.Collections;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using PHSRAG.Insight21.Common.Pages;
using PHSRAG.Insight21.Context;
using PHSRAG.Insight21.Policy;
using PHSRAG.Insight21.SearchContext;
using PHSRAG.Utility;
using PHSRAG.WebControls;
using PersonnelConstants = PHSRAG.Insight21.Personnel.Constants;
using PHSRAG.Insight21.Personnel;

namespace PHSRAG.Insight21
{
    /// <summary>
    /// The ExceptionReport class supports the ExceptionReport.aspx page.
    /// It displays the payroll exception data the currently logged-in user has access to.
    /// </summary>
    /// <remarks>
    /// The ExceptionReport page supports searching/filtering the exception data
    /// based on user-defined and user-selectable search criteria.
    /// Following is the list of such criteria:
    /// <list type="bullet">
    /// <item><description>Employee Last Name (free-form entry)</description></item>
    /// <item><description>Employee First Name (free-form entry)</description></item>
    /// <item><description>Exception message (select from a drop-down list)</description></item>
    /// </list>
    /// </remarks>
    public partial class ExceptionReport : NoCachePage
    {
        # region Constants

        private const string CurrentPageIndexKey = "CurrentPageIndex_949D1920-8CB1-4B13-9774-7D0743484DF8";
        private const string ExcelReportControlFilePath = "../../Personnel/Reports/ExceptionReportExcel.ascx";
        private const string ExceptionMessageIndex = "--Select--";
        private const string PresentDateValue = "To Present";
        private const string ReportDateColumnName = "ReportDate";
        private const string ReportDateKey = "ReportDateKey_81C78FC2-5F65-4304-B1AF-6BD3B259973A";

        #endregion

        #region Enumerations (Private)

        /// <summary>
        /// The DataGridColumns enumeration defines values 
        /// for indexing columns in the datagrid.
        /// </summary>
        private enum DataGridColumns
        {
            EmployeeJobMapId,
            EmployeeName,
            EmployeeNumber,
            RecordNumber,
            EffectiveDate,
            ExpirationDate,
            Exception
        }

        #endregion

        #region Instance Variable (Protected)

        /// <summary>Displays the current search criteria.</summary>
        protected DropDownList reportDate;

        #endregion

        #region Instance Variables (Private)

        private ICachePolicy cachePolicy;
        private ICachePolicy pageCachePolicy;

        #endregion

        #region Private Properties

        /// <summary>
        /// Get the exception informations that the logged-in user has access to. The list of payroll exceptions is
        /// is maintained by the PayrollExceptions business object within its data container. This object is cached.
        /// </summary>
        private PayrollExceptions PayrollExceptionsInstance
        {
            get
            {
                PayrollExceptions payrollExceptions =
                    ResultsCache.GetObject(cachePolicy, PayrollExceptions.CacheKey) as PayrollExceptions;

                if (payrollExceptions == null)
                {
                    payrollExceptions = new PayrollExceptions();
                    payrollExceptions.Load(DataAccess.GetConnectionString()
                        , ((UserContext) cachePolicy.GetCachedObject(UserContext.CacheKey)).DomainUserId
                        , PayrollDate);
                    ResultsCache.SetObject(cachePolicy, PayrollExceptions.CacheKey, payrollExceptions);
                }

                return payrollExceptions;
            }
        }

        /// <summary>
        /// Gets/Sets the payroll report date. 
        /// Returns an empty string if the date is not available in the page cache.
        /// Sets the selected date in the page cache.
        /// </summary>
        private string PayrollDate
        {
            get
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.PayrollReportPageKey) as Hashtable;
                return (h == null || h[Keys.ReportDateKey] == null) ? string.Empty : (string) h[Keys.ReportDateKey];
            }
            set
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.PayrollReportPageKey) as Hashtable ?? new Hashtable();
                h[Keys.ReportDateKey] = value;
                pageCachePolicy.Cache(Keys.PayrollReportPageKey, h);
            }
        }

        /// <summary>
        /// Get/Set the current page within the datagrid for display. This information persists across page loads.
        /// This information is cached using the page cache policy
        /// Get: Return the value from the page cache policy, returns 0 if its not present in cache
        /// Set: Set the value and update the cache
        /// </summary>
        private int CurrentPageIndex
        {
            get
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.ExceptionReportPageKey) as Hashtable;
                return (h == null || h[CurrentPageIndexKey] == null) ? 0 : (int) h[CurrentPageIndexKey];
            }
            set
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.ExceptionReportPageKey) as Hashtable ?? new Hashtable();
                h[CurrentPageIndexKey] = value;
                exceptionReportGrid.CurrentPageIndex = value;
                pageCachePolicy.Cache(Keys.ExceptionReportPageKey, h);
            }
        }

        #endregion

        # region Event Handlers

        # region Page Load

        /// <summary>
        /// Handler for the event raised when the page is being loaded.
        /// Initialize the bread crumb control, set the page size for the data grid, and load the data grid with data.
        /// If on the first page within the data grid, initalize the pager control.
        /// </summary>
        /// <param name="sender">Control which raised the event</param>
        /// <param name="e">Argument associated with the event</param>
        protected void OnPageLoad(object sender, EventArgs e)
        {
            annunciator.Message = string.Empty;
            annunciator.Title = string.Empty;

            reportDownload.SQLReportName = SSRSRequest.ReportNames.Personnel.ExceptionReport; //"Personnel_ExceptionReport"
            try
            {
                reportDate = (DropDownList) expandingPanel.FindControl("reportDate");

                exceptionReportBreadCrumb.Add
                    ("Exception Report", Settings.
                        GetKeyValue("SubNavigation.Personnel.ExceptionReportURL", string.Empty)
                        , Constants.DefaultSummaryPageRank);

                if (IsPostBack)
                {
                    ManagePagination();
                }
                else
                {
                    ((ExpansionToggler) expandingPanel.FindControl("expansionToggler")).HelpText =
                        InsightUtilities.Constants.SearchHelpText;

                    exceptionReportGrid.PageSize = Settings.GetKeyValue(Constants.DataGridPageSizeKey
                        , Constants.DefaultDatagridPageSize);
                    LoadPayrollReportDates();
                    SetPayrollDates();
                    ManagePagination();

                    hiddenSearchCriteria.Value = HttpUtility.UrlEncode(AddRefreshDatesToCriteria(((CommonSearchContext) cachePolicy.GetCachedObject(CommonSearchContext.CacheKey)).GetSearchCriteria(Page.Request.Url.ToString())));
                }
            }
            catch (Exception ex)
            {
                exceptionReportGrid.Visible = pagerBelowDatagrid.Visible = pagerAboveDatagrid.Visible = false;
                annunciator.Message = Utility.ExceptionReport.GetExceptionInfo(ex, false);
            }
        }

        /// <summary>
        /// This method loads the reportDates dropdownlist with the list of Payroll report dates.
        /// If there is no data to bind, warn the user via the annunciator.
        /// </summary>
        private void LoadPayrollReportDates()
        {
            try
            {
                DataTable payrollReportDates = Personnel.PayrollReport.GetPayrollReportDates();
                if (payrollReportDates.Rows.Count > 0)
                {
                    reportDate.DataSource = payrollReportDates;
                    reportDate.DataTextField = ReportDateColumnName;
                    reportDate.DataBind();
                }
                else
                {
                    annunciator.Message = "No Payroll report dates defined.";
                }
            }
            catch (Exception ex)
            {
                annunciator.Message = Utility.ExceptionReport.GetExceptionInfo(ex, false);
            }
        }

        /// <summary>
        /// This method sets the selected payroll report date in the page cache policy.
        /// Case1: If the payroll report is run for the first time, the selected report date is put into the page cache.
        /// Case2: If the selected report date doesnt match with the cached date, then uncache the existing 
        /// PayrollReport instance from the business object and set the  selected report date in the page cache.
        /// </summary>
        private void SetPayrollDates()
        {
            string payrollDate = PayrollDate;
            if (payrollDate.Equals(string.Empty))
            {
                PayrollDate = Convert.ToDateTime(reportDate.SelectedItem.Text).ToShortDateString();
            }
            else if (!payrollDate.Equals(Convert.ToDateTime(reportDate.SelectedItem.Text).ToShortDateString()))
            {
                ResultsCache.PurgeObject(cachePolicy);
                PayrollDate = Convert.ToDateTime(reportDate.SelectedItem.Text).ToShortDateString();
            }
        }

        # endregion

        #region Datagrid event handlers

        /// <summary>
        /// Handler for event raised while each data grid item is created.
        /// Help in putting the symbol denoting the sort column in the data grid.
        /// If the item being created is the data grid header:
        /// <list type="bullet">
        /// <item><description>Get the sort column and sort order from the PayrollExceptions instance in the cache</description></item>
        /// <item><description>Create a Hashtable of column indeces, keyed by the sort expression of each column</description></item>
        /// <item><description>Using the hash table add a label with sort symbol to the column on which sort has happened</description></item>
        /// </list>
        /// </summary>
        /// <param name="sender">Control which raised the event</param>
        /// <param name="e">Argument associated with the event</param>
        private void OnItemCreated(object sender, DataGridItemEventArgs e)
        {
            try
            {
                if (e.Item.ItemType == ListItemType.Header)
                {
                    PayrollExceptions payrollExceptions = PayrollExceptionsInstance;
                    Label sortSymbol = new Label();
                    sortSymbol.Text = payrollExceptions.SortAscending ? InsightUtilities.Constants.SortAscendingText : InsightUtilities.Constants.SortDescendingText;
                    sortSymbol.Font.Name = InsightUtilities.Constants.SortSymbolFontName;

                    Hashtable columnMap = new Hashtable();
                    foreach (DataGridColumn column in exceptionReportGrid.Columns)
                    {
                        columnMap[column.SortExpression] = exceptionReportGrid.Columns.IndexOf(column);
                    }

                    string sortColumn = payrollExceptions.SortColumn;
                    if (columnMap.ContainsKey(sortColumn))
                    {
                        (e.Item.Cells[(int) columnMap[sortColumn]]).Controls.Add(sortSymbol);
                    }
                }
            }
            catch (Exception ex)
            {
                exceptionReportGrid.Visible = pagerBelowDatagrid.Visible = pagerAboveDatagrid.Visible = false;
                annunciator.Message = Utility.ExceptionReport.GetExceptionInfo(ex, false);
            }
        }

        /// <summary>
        /// Handler for the event raised when a row in the datagrid is clicked upon.
        /// If the "EmployeeName" was clicked upon (its CommandName is "SelectEmployee"), load the PersonnelDetails page
        /// The page passes the selected employee's jobmapid through a dictionary.
        /// </summary>
        /// <param name="sender">Control which raised the event</param>
        /// <param name="e">Argument associated with the event</param>
        private void OnDataGridItemCommand(object sender, DataGridCommandEventArgs e)
        {
            try
            {
                if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
                {
                    if (e.CommandName == "SelectEmployee")
                    {
                        Hashtable dictionary = new Hashtable();
                        dictionary.Add(Keys.EmployeeJobMapIDKey
                            , Convert.ToInt32(e.Item.Cells[(int) DataGridColumns.EmployeeJobMapId].Text));

                        string expirationDateText = e.Item.Cells[(int) DataGridColumns.ExpirationDate].Text;

                        // If the expiration date indicates a month beyond October, we have to move the fiscal year to the next
                        // year.

                        DateTime expirationDate = (expirationDateText == PresentDateValue) ? DateTime.Now : Convert.ToDateTime(expirationDateText);
                        const int FiscalYearMonthEnd = 10;
                        if (expirationDate.Month > FiscalYearMonthEnd)
                        {
                            expirationDate = expirationDate.AddYears(1);
                        }

                        dictionary.Add(Keys.FiscalYearKey, expirationDate.Year);

                        pageCachePolicy.Cache(Keys.IncomingDataKey, dictionary);
                        PurgeCache();
                        Response.Redirect(Settings.GetKeyValue("Other.Personnel.PersonnelDetailsURL", string.Empty), false);
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.ExceptionReport.WriteToEventLog("Exception Report", ex, true, Utility.ExceptionReport.ReportType.Error);
                annunciator.Message = string.Format
                    ("Error while attempting to navigate for {0} click", e.CommandName);
            }
        }

        /// <summary>
        /// Handler for the event raised when a row in the datagrid is databound.
        ///	Sets the ExpirationDate column to "To Present" if the value retrieved from database is emtpy.
        /// </summary>
        /// <param name="sender">Control which raised the event</param>
        /// <param name="e">Argument associated with the event</param>
        private void OnItemDataBound(object sender, DataGridItemEventArgs e)
        {
            try
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    if (((PayrollException) e.Item.DataItem).ExpirationDate == string.Empty)
                    {
                        e.Item.Cells[(int) DataGridColumns.ExpirationDate].Text = PresentDateValue;
                    }
                }
            }
            catch (Exception ex)
            {
                annunciator.Message = String.Format("{0} while attempting to format columns.",
                    Utility.ExceptionReport.GetExceptionInfo(ex, false));
            }
        }

        /// <summary>
        /// Handler for the event raised when a column header within the data grid is clicked.
        /// Set the currentpageindex to 0 as sorting need to be done on all records and not only on what is visible
        /// </summary>
        /// <param name="sender">Control which raised the event</param>
        /// <param name="e">Argument associated with the event</param>
        private void OnSort(object sender, DataGridSortCommandEventArgs e)
        {
            if (e.SortExpression != string.Empty)
            {
                PayrollExceptionsInstance.Sort(e.SortExpression);
                CurrentPageIndex = 0;
                LoadDataGrid();
            }
        }

        # endregion

        #region Paging event handlers

        /// <summary>
        /// Handler for the event raised when the FirstPage link is clicked in the Pager control.
        /// Set the current page index to 0, bind the datagrid with data and manage navigation links.
        /// </summary>
        /// <param name="sender">Control which rasied the event</param>
        /// <param name="e">Arguments associated with the event</param>
        private void OnFirstPage(object sender, CommandEventArgs e)
        {
            CurrentPageIndex = 0;
            LoadDataGrid();
        }

        /// <summary>
        /// Handler for the event raised when the LastPage link is clicked in the Pager control.
        /// Set the current page index to one less than the total page count (index is 0-based), bind the datagrid with
        /// data and manage navigation links.
        /// </summary>
        /// <param name="sender">Control which rasied the event</param>
        /// <param name="e">Arguments associated with the event</param>
        private void OnLastPage(object sender, CommandEventArgs e)
        {
            CurrentPageIndex = pagerAboveDatagrid.PageCount - 1;
            LoadDataGrid();
        }

        /// <summary>
        /// Handler for the event raised when the NextPage link is clicked in the Pager control.
        /// Increment the current page index, bind the datagrid with data and manage navigation links.
        /// </summary>
        /// <param name="sender">Control which rasied the event</param>
        /// <param name="e">Arguments associated with the event</param>
        private void OnNextPage(object sender, CommandEventArgs e)
        {
            ++CurrentPageIndex;
            LoadDataGrid();
        }

        /// <summary>
        /// Handler for the event raised when the PreviousPage link is clicked in the Pager control.
        /// Decrement the current page index, bind the datagrid with data and manage navigation links.
        /// </summary>
        /// <param name="sender">Control which rasied the event</param>
        /// <param name="e">Arguments associated with the event</param>
        private void OnPreviousPage(object sender, CommandEventArgs e)
        {
            --CurrentPageIndex;
            LoadDataGrid();
        }

        #endregion

        #region Search event handler

        /// <summary>
        /// Handler for the event raised when the Search button is clicked in the Search control.
        /// Gets the search criteia and performs a search. The actual search is performed by the PersonnelSummaries object
        /// which returns true if it did indeed apply any filteration criteria, and false otherwise. This predicate
        /// is used by LoadDataGrid() to control the visibility of the pager controls.
        /// </summary>
        /// <param name="args">Search Criteria args associated with the search event</param>
        protected void OnSearch(SearchCriteriaArgs args)
        {
            SetPayrollDates();
            ProcessSearch();
        }

        /// <summary>
        /// Handler for the event raised when the "Clear Selection" button is clicked on the page.
        /// </summary>
        /// <param name="sender">Control which raised the event</param>
        /// <param name="e">Argument associated with the event</param>
        protected void OnClearSelection(object sender, CommandEventArgs e)
        {
            exceptionReportGrid.Visible = false;
            pagerAboveDatagrid.Visible = pagerBelowDatagrid.Visible = false;
        }

        #endregion

        #region Header

        /// <summary>
        /// Resets the subnavigation selected link(s) before the 
        /// header performs a redirect.
        /// </summary>
        /// <param name="sender">Control which rasied the event.</param>
        /// <param name="e">Arguments associated with the event.</param>
        private void OnHeaderNavigate(object sender, CommandEventArgs e)
        {
            personnelSubNavigation.Reset();
            PurgeCache();
        }

        #endregion

        # endregion

        #region Private Methods

        /// <summary>
        /// Load the datagrid with sufficient data for display within one page of the data grid. This is done as follows:
        /// Get the exceptions for all personnel that the user has access to. Use that to initialize the data grid and
        /// the pager controls based on the page size of the data grid.
        /// The pagers are made visible only when more than one page of data can be displayed.
        /// If there is no data to display, warn the user via the annunciator.
        /// </summary>
        private void LoadDataGrid()
        {
            try
            {
                PayrollExceptions payrollExceptions = PayrollExceptionsInstance;

                exceptionReportGrid.VirtualItemCount = pagerAboveDatagrid.RecordCount
                    = pagerBelowDatagrid.RecordCount = payrollExceptions.Count;

                int currentPageIndex = CurrentPageIndex;
                int pageCount = (pagerAboveDatagrid.RecordCount/exceptionReportGrid.PageSize) +
                    (((pagerAboveDatagrid.RecordCount%exceptionReportGrid.PageSize) == 0) ? 0 : 1);
                pagerBelowDatagrid.PageCount = pagerAboveDatagrid.PageCount = pageCount;
                pagerBelowDatagrid.CurrentPage = pagerAboveDatagrid.CurrentPage = currentPageIndex + 1;

                exceptionReportGrid.DataSource = payrollExceptions.GetPayrollExceptionList
                    (currentPageIndex*exceptionReportGrid.PageSize, exceptionReportGrid.PageSize);
                exceptionReportGrid.DataBind();

                exceptionReportGrid.Visible = pagerBelowDatagrid.Visible = pagerAboveDatagrid.Visible =
                    (exceptionReportGrid.Items.Count > 0);
                if (pagerAboveDatagrid.Visible)
                {
                    ManagePagination();
                }
                else
                {
                    annunciator.Message = "No exception data found for user";
                }
            }
            catch (Exception ex)
            {
                exceptionReportGrid.Visible = pagerBelowDatagrid.Visible = pagerAboveDatagrid.Visible = false;
                annunciator.Message = Utility.ExceptionReport.GetExceptionInfo(ex, false);
            }
        }

        /// <summary>
        /// Manages the pagination logic.
        /// Set the First record and last record values for the pager controls
        /// based on the current page index and the data grid page size respectively
        /// </summary>
        private void ManagePagination()
        {
            if (pagerBelowDatagrid.Visible = pagerAboveDatagrid.Visible = (exceptionReportGrid.Items.Count > 0))
            {
                int currentPageIndex = CurrentPageIndex;
                exceptionReportGrid.CurrentPageIndex = currentPageIndex;

                int startIndex = currentPageIndex*exceptionReportGrid.PageSize;

                pagerBelowDatagrid.FirstRecord = pagerAboveDatagrid.FirstRecord = startIndex + 1;
                pagerBelowDatagrid.LastRecord = pagerAboveDatagrid.LastRecord =
                    Math.Min(startIndex + exceptionReportGrid.PageSize, exceptionReportGrid.VirtualItemCount);

                pagerBelowDatagrid.EnableFirstPage = pagerAboveDatagrid.EnableFirstPage =
                    pagerBelowDatagrid.EnablePreviousPage = pagerAboveDatagrid.EnablePreviousPage =
                        (CurrentPageIndex != 0);

                pagerBelowDatagrid.EnableLastPage = pagerAboveDatagrid.EnableLastPage =
                    pagerBelowDatagrid.EnableNextPage = pagerAboveDatagrid.EnableNextPage =
                        (CurrentPageIndex != (pagerAboveDatagrid.PageCount - 1));
            }
        }

        /// <summary>
        /// Adds refresh dates currently visible on the page to the search criteria string
        /// to be passed down to reports. The criteria does not persist to the SearchCriteria
        /// object.
        /// </summary>
        /// <param name="searchCriteria">Object containing search criteria.</param>
        /// <returns>A string representation of search criteria. </returns>
        private string AddRefreshDatesToCriteria(SearchCriteria searchCriteria)
        {
            StringBuilder criteria = new StringBuilder(searchCriteria.ToString(";"));
            if (refreshDates.SalaryAsOfDateVisible)
            {
                criteria.AppendFormat("Last Salary Post|{0};", refreshDates.SalaryAsOfDate.ToShortDateString());
            }
            if (refreshDates.GLAsOfDateVisible)
            {
                criteria.AppendFormat("Last GL Post|{0};", refreshDates.GLPostAsOfDate.ToShortDateString());
            }
            if (refreshDates.POAPAsOfDateVisible)
            {
                criteria.AppendFormat("Last PO/AP Post|{0};", refreshDates.POAPAsOfDate.ToShortDateString());
            }
            criteria.AppendFormat("Report date|{0:d};", PayrollDate);
            return criteria.ToString();
        }

        /// <summary>
        /// Search the exception message data for the specified search criteria
        /// </summary>
        private void ProcessSearch()
        {
            try
            {
                CommonSearchContext searchContext = (CommonSearchContext) cachePolicy.GetCachedObject(CommonSearchContext.CacheKey);
                SearchCriteria searchCriteria = searchContext.GetSearchCriteria(Page.Request.Url.ToString());

                PayrollExceptionsInstance.Search
                    (searchCriteria);
                CurrentPageIndex = 0;
                LoadDataGrid();
                ManagePagination();

                hiddenSearchCriteria.Value = HttpUtility.UrlEncode(AddRefreshDatesToCriteria(searchCriteria));
            }
            catch (Exception ex)
            {
                exceptionReportGrid.Visible = pagerBelowDatagrid.Visible = pagerAboveDatagrid.Visible = false;
                annunciator.Message = Utility.ExceptionReport.GetExceptionInfo(ex, false);
            }
        }

        #endregion

        #region Web Form Designer generated code

        /// <summary>
        /// Handler for the event raised when the page is being initialized.
        /// Retrieve the cache policy and page cache policy in force.
        /// Deposit event handlers to support the datagrid pagination.
        /// </summary>
        /// <param name="e">Argument associated with the event</param>
        protected override void OnInit(EventArgs e)
        {
            cachePolicy = (Policy.ICachePolicy) Session[Policy.Names.CachePolicyKey];
            pageCachePolicy = (Policy.ICachePolicy) Session[Policy.Names.PageCachePolicyKey];

            InitializeComponent();
            base.OnInit(e);

            pagerAboveDatagrid.FirstPage += new CommandEventHandler(this.OnFirstPage);
            pagerAboveDatagrid.LastPage += new CommandEventHandler(this.OnLastPage);
            pagerAboveDatagrid.NextPage += new CommandEventHandler(this.OnNextPage);
            pagerAboveDatagrid.PreviousPage += new CommandEventHandler(this.OnPreviousPage);

            pagerBelowDatagrid.FirstPage += new CommandEventHandler(this.OnFirstPage);
            pagerBelowDatagrid.LastPage += new CommandEventHandler(this.OnLastPage);
            pagerBelowDatagrid.NextPage += new CommandEventHandler(this.OnNextPage);
            pagerBelowDatagrid.PreviousPage += new CommandEventHandler(this.OnPreviousPage);
        }

        /// <summary>
        /// Required method for Designer support
        /// </summary>
        private void InitializeComponent()
        {
            this.insightHeader.Navigate += new System.Web.UI.WebControls.CommandEventHandler(this.OnHeaderNavigate);
            this.personnelSubNavigation.Navigate += new System.Web.UI.WebControls.CommandEventHandler(this.OnSubHeaderNavigate);
            this.exceptionReportBreadCrumb.Navigate += new System.Web.UI.WebControls.CommandEventHandler(this.OnBreadCrumbNavigate);
            this.exceptionReportGrid.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.OnItemCreated);
            this.exceptionReportGrid.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.OnDataGridItemCommand);
            this.exceptionReportGrid.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.OnSort);
            this.exceptionReportGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.OnItemDataBound);
            this.Load += new System.EventHandler(this.OnPageLoad);
        }

        #endregion

        private void OnSubHeaderNavigate(object sender, CommandEventArgs e)
        {
            PurgeCache();
        }

        private void OnBreadCrumbNavigate(object sender, CommandEventArgs e)
        {
            PurgeCache();
        }

        public void PurgeCache()
        {
            ResultsCache.PurgeObject(cachePolicy);
        }
    }
}